bitwise operation位运算相关

1. How to check odd number

n & 1 means comparing last digit of binary number to 1

1
2
def is_odd(n):
return n & 1 == 1

2. Float division

n >> 1 means n floor divides 2

1
2
>>> 5 >> 1
2